import java.util.List;

public class MyQueue {


    private int[]elem;
    private int front;
    private int rear;

    public MyQueue(){
        elem=new int[10];
    }

    //检查队列是否为满的方法
    private void checkFull(){
        if(isFull()){
            throw new OfferFullException();
        }
    }
    //入队方法
    public int offer(int val){
        //判满抛出异常
        try{
            checkFull();
        }catch (OfferFullException e){
            e.printStackTrace();
        }
        elem[rear]=val;
        rear=(rear+1)%elem.length;
        return val;
    }

    //检查队列是否为空的方法
    private void checkEmpty(){
        if(isEmpty()){
            throw new PollEmptyException();
        }
    }

    //出队方法
    public int poll(){
        //判空抛出异常
        try{
            checkEmpty();
        }catch (PollEmptyException e){
            e.printStackTrace();
        }
         int val=elem[front];
        front=(front+1)%elem.length;
        return val;
    }

    //获取队头元素方法
    public int peek(){
        //判空抛出异常
        try{
            checkEmpty();
        }catch (PollEmptyException e){
            e.printStackTrace();
        }
        return elem[front];
    }

    //判断队列是否为空方法
    public boolean isEmpty(){
        return front==rear;
    }

    //判断队列是否为满方法
    public boolean isFull(){
        return (rear+1)%elem.length==front;
    }

}
